package com.future.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.future.po.MonitorDevice;
import com.future.service.DeviceService;
import com.future.vo.ResponseResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "设备的API接口")
@RestController
@CrossOrigin
@RequestMapping("/device")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;


    @ApiOperation(value = "获取所有设备信息")
    @GetMapping("list")
    public ResponseResultVo deviceList() {

        return ResponseResultVo.success( deviceService.list());
    }

    @ApiOperation(value = "获得现在指定序列号的设备的信息")
    @GetMapping("get")
    public ResponseResultVo getBySerialNumber(@RequestParam String serialNumber) {
        LambdaQueryWrapper<MonitorDevice> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MonitorDevice::getSerialNumber,serialNumber);

        return ResponseResultVo.success( deviceService.getOne(wrapper));
    }

    @ApiOperation(value = "获得现在指定id的设备的信息")
    @GetMapping("get/{id}")
    public ResponseResultVo getById(@PathVariable String id) {
        LambdaQueryWrapper<MonitorDevice> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(MonitorDevice::getUid,id);

        return ResponseResultVo.success( deviceService.getOne(wrapper));
    }


}
